package com.ssm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ssm.bean.Device;
import com.ssm.dao.DeviceMapper;
import com.ssm.service.DeviceService;

@Service
public class DeviceServiceImpl implements DeviceService {

	@Autowired
	private DeviceMapper deviceMapper;
	
	@Override
	public List<Device> getAllDevices() {
		return deviceMapper.getAllDevices();
	}
	
	@Override
	public int getDevicesCnt(Map<String,Object> params) {
		return deviceMapper.getDevicesCnt(params);
	}
	
	@Override
	@Transactional
	public List<Device> getDevices(Map<String,Object> params) {
		return deviceMapper.getDevices(params);
	}
	
	@Override
	public Device getDeviceByIp(String ipAddress) {
		return deviceMapper.getDeviceByIp(ipAddress);
	}

	@Override
	public void insertDevice(Device device) {
		deviceMapper.insertDevice(device);
		
	}

	@Override
	public void updateDevice(Device device) {
		deviceMapper.updateDevice(device);
		
	}

	@Override
	@Transactional
	public void deleteDevices(List<String> ipAddress) {
		try{
			deviceMapper.deleteDevices(ipAddress);
		}catch(Exception e){
			throw new RuntimeException();
		}
		
	}

	@Override
	public int isRepeated(String ipAddress) {
		return deviceMapper.isRepeated(ipAddress);
		
	}

}
